package com.project_doctor.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.http.ResponseEntity;
import com.project_doctor.service.DashboardService;

import java.util.Map;

/**
 * 数据看板控制器
 */
@RestController
@RequestMapping("/dashboard")
@CrossOrigin
public class DashboardController {

    @Autowired
    private DashboardService dashboardService;

    /**
     * 获取数据概览信息
     * @return 概览数据
     */
    @GetMapping("/overview")
    public ResponseEntity<Map<String, Object>> getOverviewData() {
        try {
            Map<String, Object> data = dashboardService.getOverviewData();
            return ResponseEntity.ok(data);
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseEntity.internalServerError().build();
        }
    }

    /**
     * 获取趋势数据
     * @return 趋势图表数据
     */
    @GetMapping("/trend")
    public ResponseEntity<Map<String, Object>> getTrendData() {
        try {
            Map<String, Object> data = dashboardService.getTrendData();
            return ResponseEntity.ok(data);
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseEntity.internalServerError().build();
        }
    }

    /**
     * 获取待办事项数据
     * @return 待办事项列表
     */
    @GetMapping("/todo")
    public ResponseEntity<Map<String, Object>> getTodoData() {
        try {
            Map<String, Object> data = dashboardService.getTodoData();
            return ResponseEntity.ok(data);
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseEntity.internalServerError().build();
        }
    }

    /**
     * 获取标签统计数据
     * @return 标签分布统计
     */
    @GetMapping("/tags")
    public ResponseEntity<Map<String, Object>> getTagStats() {
        try {
            Map<String, Object> data = dashboardService.getTagStats();
            return ResponseEntity.ok(data);
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseEntity.internalServerError().build();
        }
    }

    /**
     * 获取医生卡片数据
     * @return 医生信息卡片列表
     */
    @GetMapping("/doctors")
    public ResponseEntity<Map<String, Object>> getDoctorCards() {
        try {
            Map<String, Object> data = dashboardService.getDoctorCards();
            return ResponseEntity.ok(data);
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseEntity.internalServerError().build();
        }
    }

    /**
     * 获取周统计数据
     * @return 本周各项数据统计
     */
    @GetMapping("/weekly")
    public ResponseEntity<Map<String, Object>> getWeeklyData() {
        try {
            Map<String, Object> data = dashboardService.getWeeklyData();
            return ResponseEntity.ok(data);
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseEntity.internalServerError().build();
        }
    }
}